package com.test;

import java.util.Collection;
import java.util.Map;

public class CollectionRuleNode extends RuleNode{
	Object itemKey = null;
	public CollectionRuleNode(Object itemKey){
		this.itemKey =itemKey;
	}
	@Override
	public MatchResult howMatch(JsonKey key, Class type, Object value) {
		
		if(key==null){
			if(value instanceof Collection || value instanceof Map){
				return new MatchResult(this,this.action);
			}else{
				return null;
			}
			
		}
		
		if(key.getName().equals(itemKey)){
			return new MatchResult(this.nextRule,this.action);
		}else{
			return null;
		}
	}
	
	@Override
	public String toString() {
		return "CollectionRuleNode [itemKey=" + itemKey + "]";
	}

	
}
